package cc.vv.btpartyjob.partyservice.delegate

import android.view.View
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.baselibrary.view.BtWebView
import cc.vv.btpartyjob.jnimodule.R
import cc.vv.mvp.delegate.BaseAppDelegate
import com.tencent.smtt.sdk.CacheManager
import com.tencent.smtt.sdk.WebChromeClient
import com.tencent.smtt.sdk.WebSettings
import com.tencent.smtt.sdk.WebViewClient

/**
 * Web详情托管类
 * Created by Chen.qi on 2018/10/30.
 */
class WebDetailActivityDelegate : BaseAppDelegate() {

    override fun initWidget() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.activity_web
    }

    /**设置标题title*/
    fun setTopBarTitle(topBarTitle: String?) {
        val titleBar = getView<BaseTopBarView>(R.id.btv_awJni_topBar)
        titleBar?.setTitle(topBarTitle)
    }

    /**设置右边标题title*/
    fun setRightTitle(right: String?) {
        val titleBar = getView<BaseTopBarView>(R.id.btv_awJni_topBar)
        titleBar?.setRightTVContent(right)
    }

    /**设置右边图标title*/
    fun setRightPic(type: String?) {
        val titleBar = getView<BaseTopBarView>(R.id.btv_awJni_topBar)
        when (type) {
            "0" -> {
                titleBar?.rl_ljtb_right_layout?.visibility = View.GONE
            }
            "1" -> {
                titleBar?.rl_ljtb_right_layout?.visibility = View.VISIBLE
                titleBar?.setRightBtnImage(R.mipmap.icon_top_choose_time)
            }
            "2" -> {
                titleBar?.rl_ljtb_right_layout?.visibility = View.VISIBLE
                titleBar?.setRightBtnImage(R.mipmap.icon_party_zuzhi_search)
            }
            "3" -> {
                titleBar?.rl_ljtb_right_layout?.visibility = View.VISIBLE
                titleBar?.setRightBtnImage(R.mipmap.icon_party_zuzhi_search)
            }
        }
    }


    /**设置标题右边按钮点击事件*/
    fun setTitleBackBtnOnClick(event: BaseTopBarView.EventInterface) {
        val titleBar = getView<BaseTopBarView>(R.id.btv_awJni_topBar)
        titleBar?.setEventInterface(event)
    }


    fun initWebClient(webViewClient: WebViewClient, webCromeClient: WebChromeClient) {
        val webView = getView<BtWebView>(R.id.bwv_awJni_webView)
        webView?.setWebViewClient(webViewClient)
        webView?.setWebChromeClient(webCromeClient)
    }


    fun setWebViewUrl(webUrl: String) {
        val webView = getView<BtWebView>(R.id.bwv_awJni_webView)
        webView?.settings?.cacheMode = WebSettings.LOAD_NO_CACHE
        webView?.loadUrl(webUrl)
    }

    fun getWebView(): BtWebView {
        return getView(R.id.bwv_awJni_webView)
    }
}